package com.egao.api.controller.orderB;


import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.service.OperRecordService;
import com.egao.orderB.entity.Area;
import com.egao.orderB.service.AreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

//import com.egao.orderB.entity.Bill;
//import com.egao.orderB.service.BillService;

/**
 * api登录相关接口
 * Created by wangfan on 2019-05-29 下午 3:43.
 * http://localhost/swagger-ui.html
 */
@RequestMapping("/api/area")
@RestController
@Api(value = "区",tags = {"区"})
public class ApiAreaController extends BaseController {
    @Autowired
    private OperRecordService operRecordService;
    @Autowired
    private AreaService areaService;

    /**
     * 运费维护列表
     */
    @PostMapping("/list")
    @ApiOperation(value = "区列表",notes = "" +
            "limit:每页显示几行 必填\n" +
            "page:第几页 必填\n" +
            "返回的字段:\n" +
            "id:id\n" +
            "organizationId:组织id\n" +
            "areaId:id\n" +
            "area:名称\n" +
            "father:父id\n" +
            "createTime:创建时间\n" +
            "createUser:创建人\n" +
            "updateTime:更新时间\n" +
            "updateUser:更新人\n" +
            "deleted:del(0正常 1删除)\n" +
            "",httpMethod = "POST")
    public JsonResult list(PageResult2<T> page, Area area, HttpServletRequest request)  throws Exception{
        return areaService.list(page, area, getLoginUser());
    }

    /**
     * 添加运费维护列表
     */
    @PostMapping("/listAll")
    @ApiOperation(value = "区列表",notes = "" +
            "father:父id\n" +
            "",httpMethod = "POST")
    public JsonResult listAll(Area area, HttpServletRequest request)  throws Exception{
        return areaService.list(area, getLoginUser());
    }

    /**
     * 添加区
     */
    @OperLog(value = "区", desc = "添加区", result = true)
    @PostMapping("/save")
    @ApiOperation(value = "添加区",notes = "\n" +
            "areaId:id\n" +
            "area:名称\n" +
            "father:父id\n" +
            "",httpMethod = "POST")
    public JsonResult save(Area area, HttpServletRequest request) {
        return areaService.save(area, getLoginUser());
    }


    /**
     * 修改区
     */
    @PreAuthorize("hasAuthority('orderB:area:update')")
    @OperLog(value = "区", desc = "修改区", result = true)
    @PostMapping("/update")
    @ApiOperation(value = "修改区",notes = "" +
            "id:id 必填\n" +
            "areaId:id\n" +
            "area:名称\n" +
            "father:父id\n" +
            "",httpMethod = "POST")
    public JsonResult update(Area area, HttpServletRequest request) {
        return areaService.update(area, getLoginUser());
    }

    /**
     * 删除区
     */
    @PreAuthorize("hasAuthority('orderB:area:remove')")
    @OperLog(value = "区", desc = "删除")
    @PostMapping("/remove")
    @ApiOperation(value = "删除区",notes = "id:id必填",httpMethod = "POST")
    public JsonResult remove(Area area, HttpServletRequest request) {
        return areaService.remove(area, getLoginUser());
    }

}
